﻿using System;
using System.Text;

namespace HslCommunication.Profinet.Yokogawa
{
	/// <summary>
	/// 横河PLC的系统基本信息<br />
	/// Basic system information of Yokogawa PLC
	/// </summary>
	// Token: 0x02000042 RID: 66
	public class YokogawaSystemInfo
	{
		/// <summary>
		/// 当前系统的ID名称，例如F3SP21-ON<br />
		/// The ID name of the current system, such as F3SP21-ON
		/// </summary>
		// Token: 0x1700012F RID: 303
		// (get) Token: 0x060005A7 RID: 1447 RVA: 0x0001A248 File Offset: 0x00018448
		// (set) Token: 0x060005A8 RID: 1448 RVA: 0x0001A250 File Offset: 0x00018450
		public string SystemID { get; set; }

		/// <summary>
		/// 当前系统的修订版本号<br />
		/// The revision number of the current system
		/// </summary>
		// Token: 0x17000130 RID: 304
		// (get) Token: 0x060005A9 RID: 1449 RVA: 0x0001A259 File Offset: 0x00018459
		// (set) Token: 0x060005AA RID: 1450 RVA: 0x0001A261 File Offset: 0x00018461
		public string Revision { get; set; }

		/// <summary>
		/// 当前系统的类型，分为 <b>Sequence</b> 和 <b>BASIC</b> <br />
		/// The type of the current system, divided into <b>Sequence</b> and <b>BASIC</b>
		/// </summary>
		// Token: 0x17000131 RID: 305
		// (get) Token: 0x060005AB RID: 1451 RVA: 0x0001A26A File Offset: 0x0001846A
		// (set) Token: 0x060005AC RID: 1452 RVA: 0x0001A272 File Offset: 0x00018472
		public string CpuType { get; set; }

		/// <summary>
		/// 当前系统的程序大小，如果是Sequence系统，就是步序总量，如果是BASIC系统，就是字节数量<br />
		/// The program size of the current system, if it is a Sequence system, it is the total number of steps, if it is a BASIC system, it is the number of bytes
		/// </summary>
		// Token: 0x17000132 RID: 306
		// (get) Token: 0x060005AD RID: 1453 RVA: 0x0001A27B File Offset: 0x0001847B
		// (set) Token: 0x060005AE RID: 1454 RVA: 0x0001A283 File Offset: 0x00018483
		public int ProgramAreaSize { get; set; }

		/// <inheritdoc />
		// Token: 0x060005AF RID: 1455 RVA: 0x0001A28C File Offset: 0x0001848C
		public override string ToString()
		{
			return "YokogawaSystemInfo[" + this.SystemID + "]";
		}

		/// <summary>
		/// 根据原始的数据信息解析出<see cref="T:HslCommunication.Profinet.Yokogawa.YokogawaSystemInfo" />对象<br />
		/// Analyze the <see cref="T:HslCommunication.Profinet.Yokogawa.YokogawaSystemInfo" /> object according to the original data information
		/// </summary>
		/// <param name="content">原始的数据信息</param>
		/// <returns>是否解析成功的结果对象</returns>
		// Token: 0x060005B0 RID: 1456 RVA: 0x0001A2A4 File Offset: 0x000184A4
		public static OperateResult<YokogawaSystemInfo> Prase(byte[] content)
		{
			OperateResult<YokogawaSystemInfo> result;
			try
			{
				YokogawaSystemInfo yokogawaSystemInfo = new YokogawaSystemInfo();
				yokogawaSystemInfo.SystemID = Encoding.ASCII.GetString(content, 0, 16).Trim(new char[]
				{
					'\0',
					' '
				});
				yokogawaSystemInfo.Revision = Encoding.ASCII.GetString(content, 16, 8).Trim(new char[]
				{
					'\0',
					' '
				});
				bool flag = content[25] == 1 || content[25] == 17;
				if (flag)
				{
					yokogawaSystemInfo.CpuType = "Sequence";
				}
				else
				{
					bool flag2 = content[25] == 2 || content[25] == 18;
					if (flag2)
					{
						yokogawaSystemInfo.CpuType = "BASIC";
					}
					else
					{
						yokogawaSystemInfo.CpuType = StringResources.Language.UnknownError;
					}
				}
				yokogawaSystemInfo.ProgramAreaSize = (int)content[26] * 256 + (int)content[27];
				result = OperateResult.CreateSuccessResult<YokogawaSystemInfo>(yokogawaSystemInfo);
			}
			catch (Exception ex)
			{
				result = new OperateResult<YokogawaSystemInfo>(string.Concat(new string[]
				{
					"Prase YokogawaSystemInfo failed: ",
					ex.Message,
					Environment.NewLine,
					"Source: ",
					content.ToHexString(' ')
				}));
			}
			return result;
		}
	}
}
